﻿using System;
using System.Collections.Generic;
using System.Text;
using DBUtility;
using ATSIDAL;
using ATSModel;
using System.Data.SqlClient;
using System.Data;

namespace ATSDAL
{
    public class TCalIntermodulation : BaseRepository_DT<TCalIntermodulationItem>, ITCalIntermodulationItem
    {
        private const String PRAM_Cali_RecordTime = "@RecordTime";
        private const String PRAM_Cali_InstrumentID = "@InstrumentID";
        private const String PRAM_Cali_Time1 = "@Time1";
        private const String PRAM_Cali_Value1 = "@Value1";
        private const String PRAM_Cali_Time2 = "@Time2";
        private const String PRAM_Cali_Value2 = "@Value2";
        private const String PRAM_Cali_Time3 = "@Time3";
        private const String PRAM_Cali_Value3 = "@Value3";
        private const String PRAM_Cali_Time4 = "@Time4";
        private const String PRAM_Cali_Value4 = "@Value4";
        private const String PRAM_Cali_Time5 = "@Time5";
        private const String PRAM_Cali_Value5 = "@Value5";
        private const String PRAM_Cali_UserID = "@UserID";
        private const String PRAM_Cali_UserID2 = "@UserID2";
        private const String PRAM_Cali_InstrumentID1 = "@InstrumentID1";
        public IList<TCalIntermodulationItem> LoadEntities()
        {
            return null;
        }

        public TCalIntermodulationItem LoadEntity<T1>(T1 Id)
        {
            return null;
        }
        public IList<TCalIntermodulationItem> GetIntermodulationItemByDT(DateTime starttime, DateTime stoptime)
        {
            SqlParameter[] testParms = GetDTParameters();

            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;

            return ExcuteSqlToGetEntities("CalIntermodulRecordBYDT", testParms);
        
        }
        public IList<TCalIntermodulationItem> GetIntermodulationItemBySN(String InstrumentID)
        {
            SqlParameter parm = new SqlParameter(PRAM_Cali_InstrumentID, SqlDbType.NVarChar, 50);
            parm.Value = InstrumentID;
            return ExcuteSqlToGetEntities("CalRecord_select_SN", parm);
        
        }
        public  IList<TCalIntermodulationItem> GetIntermodulationItem()
        {
          return ExcuteSqlToGetEntities("CalIntermodulRecord");
        
        }
        public IList<TCalIntermodulationItem> GetIntermodulationItemByDTAndSN(DateTime starttime, DateTime stoptime, string InstrumentID)
        {
            SqlParameter[] ptestParms = GetUserDTParameters();
            ptestParms[0].Value = starttime;
            ptestParms[1].Value = stoptime;
            ptestParms[2].Value = InstrumentID;
            return ExcuteSqlToGetEntities("CalIntermodulRecordBYDTAndSN", ptestParms);
        
        }
        public override TCalIntermodulationItem GetEntityRecord(SqlDataReader rdr)
        {
            TCalIntermodulationItem pro = new TCalIntermodulationItem
            {
                RecordTime = rdr.GetValue(0).ToString(),
                InstrumentID = rdr.GetValue(1).ToString(),
                Time1 = rdr.GetValue(2).ToString(),
                Value1 = rdr.GetValue(3).ToString(),
                Time2 = rdr.GetValue(4).ToString(),
                Value2 = rdr.GetValue(5).ToString(),
                Time3 = rdr.GetValue(6).ToString(),
                Value3 = rdr.GetValue(7).ToString(),
                Time4 = rdr.GetValue(8).ToString(),
                Value4 = rdr.GetValue(9).ToString(),
                Time5 = rdr.GetValue(10).ToString(),
                Value5 = rdr.GetValue(11).ToString(),
                UserID = rdr.GetValue(12).ToString(),
                UserID2 = rdr.GetValue(13).ToString()

            };
            return pro;
        }

        public override TCalIntermodulationItem GetEntityRecord()
        {
            TCalIntermodulationItem pro = new TCalIntermodulationItem();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "TTest_Insert1";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }



        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PRAM_Cali_RecordTime, SqlDbType.NVarChar, 100),
					new SqlParameter(PRAM_Cali_InstrumentID, SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_Time1, SqlDbType.NVarChar, 100),
                    new SqlParameter(PRAM_Cali_Value1, SqlDbType.NVarChar, 50),
                     new SqlParameter(PRAM_Cali_Time2, SqlDbType.NVarChar, 100),
                    new SqlParameter(PRAM_Cali_Value2, SqlDbType.NVarChar, 50),
                     new SqlParameter(PRAM_Cali_Time3, SqlDbType.NVarChar, 100),
                    new SqlParameter(PRAM_Cali_Value3, SqlDbType.NVarChar, 50),
                     new SqlParameter(PRAM_Cali_Time4, SqlDbType.NVarChar, 100),
                    new SqlParameter(PRAM_Cali_Value4, SqlDbType.NVarChar, 50),
                     new SqlParameter(PRAM_Cali_Time5, SqlDbType.NVarChar, 100),
                    new SqlParameter(PRAM_Cali_Value5, SqlDbType.NVarChar, 50),
                    new SqlParameter(PRAM_Cali_UserID, SqlDbType.NVarChar, 50),
					new SqlParameter(PRAM_Cali_UserID2, SqlDbType.NVarChar, 50)        
                    
                };
            return parms;
        }

        public override void SetParameters(TCalIntermodulationItem tpti, params SqlParameter[] Parms)
        {
            Parms[0].Value = tpti.RecordTime;
            Parms[1].Value = tpti.InstrumentID;
            Parms[2].Value = tpti.Time1;
            Parms[3].Value = tpti.Value1;
            Parms[4].Value = tpti.Time2;
            Parms[5].Value = tpti.Value1;
            Parms[6].Value = tpti.Time3;
            Parms[7].Value = tpti.Value1;
            Parms[8].Value = tpti.Time4;
            Parms[9].Value = tpti.Value1;
            Parms[10].Value = tpti.Time5;
            Parms[11].Value = tpti.Value1;
            Parms[12].Value = tpti.UserID;
            Parms[13].Value = tpti.UserID2;


        }

        private SqlParameter[] GetUserDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
            {
                new SqlParameter(PARM_STARTTIME, SqlDbType.DateTime,8),
                new SqlParameter(PARM_STOPTIME, SqlDbType.DateTime,8),
                new SqlParameter(PRAM_Cali_InstrumentID1, SqlDbType.NVarChar, 50),
             
            };
            return parms;
        }

    }
}
